import requests

# 基础 URL
BASE_URL = "https://httpbin.org"

# GET: /bearer
# Prompts the user for authorization using bearer authentication.
# parameters: Authorization; string, (header)
# responses: 200(Successful authentication), 401(Unsuccessful authentication)
def bearer_auth():
    valid_token = "Bearer Token123"
    invalid_token = "InvalidToken"

    # 测试有效的 Bearer Token
    valid_headers = {"Authorization": f"{valid_token}"}
    valid_response = requests.get(f"{BASE_URL}/bearer", headers=valid_headers)
    print("Valid Token Response:")
    print(valid_response.status_code)
    print(valid_response.headers)
    print(valid_response.json())

    # 测试无效的 Bearer Token
    invalid_headers = {"Authorization": f"{invalid_token}"}
    invalid_response = requests.get(f"{BASE_URL}/bearer", headers=invalid_headers)
    try:
        print("Invalid Token Response:")
        print(invalid_response.status_code)
        print(invalid_response.headers)
        print(invalid_response.json())
    except Exception as e:
        print("Invalid Token Response:", e)

# 运行测试
bearer_auth()